<template>
	<view>
		<!-- 返回首页 -->
		<uni-bankhome />
		<view class="-list">
			<view class="title">提现金额</view>
			<view class="content">
				<view class="price">
					<span style="margin-right:5px;"></span>
					<div class="money">
						<span>{{price}}</span>
						<span class="line"></span>
					</div>
				</view>

				<view class="all">
					<view @click="handleAll" :style="{ color: $mainColor }">全部</view>
					<view style="font-size: 24rpx; color: #999">可提现金额<span>{{ walletNum | unitPrice }}</span></view>
				</view>

			</view>
			<!-- <view class="tips">
				{{rmb}}
			</view> -->
		</view>
		<div class="jsq-wrapper">
			<div class="flex">
				<div class="box one">
					<div class="inner" @click="operate(1)">1</div>
				</div>
				<div class="box two">
					<div class="inner" @click="operate(2)">2</div>
				</div>
				<div class="box three">
					<div class="inner" @click="operate(3)">3</div>
				</div>
				<div class="box del">
					<div class="inner" @click="operate('del')">删除</div>
				</div>
			</div>
			<div class="flex">
				<div class="flex-75">
					<div class="flex">
						<div class="box four">
							<div class="inner" @click="operate(4)">4</div>
						</div>
						<div class="box five">
							<div class="inner" @click="operate(5)">5</div>
						</div>
						<div class="box six">
							<div class="inner" @click="operate(6)">6</div>
						</div>
					</div>
					<div class="flex">
						<div class="box seven">
							<div class="inner" @click="operate(7)">7</div>
						</div>
						<div class="box eight">
							<div class="inner" @click="operate(8)">8</div>
						</div>
						<div class="box nine">
							<div class="inner" @click="operate(9)">9</div>
						</div>
					</div>
					<div class="flex">
						<div class="box zero">
							<div class="inner" @click="operate(0)">0</div>
						</div>
						<div class="box dian">
							<div class="inner" @click="operate('.')">.</div>
						</div>
					</div>
				</div>
				<div class="box pay">
					<div class="inner" @click="cashd">提现</div>
				</div>
			</div>
		</div>
	</view>
</template>
<script>
	import {
		getUserWallet,
		withdrawalApply,
		GetCommission
	} from "@/api/members";
	export default {
		data() {
			return {
				rmb: 0,
				price: '',
				walletNum: 0,
				type: ''
			};
		},
		onLoad(option) {
			// console.log(option)
			this.type = option.type
		},
		mounted() {
			if (this.type == 'sale') {
				Promise.all([
					GetCommission({
						owner: 'SALE'
					}), //销售钱包余额
				]).then((res) => {
					this.walletNum = res[0].data.result.memberWallet
				});
			} else {
				Promise.all([
					GetCommission({
						owner: 'PROMOTE'
					}), //推广钱包余额
				]).then((res) => {
					this.walletNum = res[0].data.result.memberWallet
				});
			}
		},

		methods: {
			operate(param) {
				if (param == 'pay') {
					return
				}
				if (param == 'del') {
					if (this.price.length > 0) {
						this.price = this.price.slice(0, this.price.length - 1)
					}
					return
				}
				let money = this.price + param + ''
				if ((/^([1-9]\d{0,9}|0)([.]?|(\.\d{1,2})?)$/.test(money)) == true) {
					this.price = money
				} else {
					return
				}
			},
			cashd() {
				if (this.type == 'sale') {
					this.price = this.price + "";
					let userInfo = this.$options.filters.isLogin() || {}
					if (this.$u.test.amount(parseFloat(this.price))) {
						withdrawalApply({
							price: this.price,
							owner: 'STORE_SALE'
						}).then((res) => {
							if (res.data.success) {
								uni.showToast({
									title: "提现成功!",
									duration: 2000,
									icon: "none",
								});
								setTimeout(() => {
									uni.navigateBack({
										delta: 1,
									});
								}, 1000);
							} else {
								uni.showToast({
									icon: "none",
									title: res.data.message
								})
							}
						});
					} else {
						uni.showToast({
							title: "请输入正确金额",
							duration: 2000,
							icon: "none",
						});
					}
				} else {
					this.price = this.price + "";
					let userInfo = this.$options.filters.isLogin() || {}
					if (this.$u.test.amount(parseFloat(this.price))) {
						withdrawalApply({
							price: this.price,
							owner: userInfo.haveStore ? 'STORE_PROMOTE' : 'BUYER_PROMOTE'
						}).then((res) => {
							if (res.data.success) {
								uni.showToast({
									title: "提现成功!",
									duration: 2000,
									icon: "none",
								});
								setTimeout(() => {
									uni.navigateBack({
										delta: 1,
									});
								}, 1000);
							} else {
								uni.showToast({
									icon: "none",
									title: res.data.message
								})
							}
						});
					} else {
						uni.showToast({
							title: "请输入正确金额",
							duration: 2000,
							icon: "none",
						});
					}
				}
			},
			handleAll() {
				this.price = this.walletNum + '';
			},
		},
	};
</script>
<style lang="scss" scoped>
	@import "./style.scss";

	.tips {
		font-size: 32upxx;
		color: #999;
	}
</style>
